/*
 * Lenovo Group
 * Copyright (c) 2015-2016 All Rights Reserved.
 * Project Name: lmrp-android app
 * Create Time: 16-2-16 下午6:44
 */

package com.lenovo.mso2o.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CompoundButton;

import com.lenovo.framework.FApplication;
import com.lenovo.framework.base.ActionBarFragmentActivity;
import com.lenovo.framework.base.ActionBarInterface;
import com.lenovo.framework.rx.RxBus;
import com.lenovo.mso2o.R;
import com.lenovo.mso2o.conf.MSConstants;

import java.util.concurrent.TimeUnit;

import rx.functions.Action1;

public class OrderGrabListFragment extends OrderFilterFragment implements ActionBarInterface, View.OnClickListener, CompoundButton.OnCheckedChangeListener{

    public static final String REFRESH_LIST = "order_list_refresh";
    private RxBus rxBus;


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        rxBus = FApplication.getRxBus();
        rxBus.toObserverable()
                .compose(this.bindToLifecycle())
                .debounce(MSConstants.REFRESH_DURATION, TimeUnit.SECONDS)
                .subscribe(new Action1<Object>() {
                    @Override
                    public void call(Object o) {
                        if (o.equals(REFRESH_LIST))
                            onRefresh(true);
                    }
                });
    }

    @Override
    protected void onFragmentInVisible(Bundle savedInstanceState) {}

    @Override
    protected void onFragmentVisible(Bundle savedInstanceState) {

    }

    @Override
    public int getActionBarRight2ResourceId(){
        //return R.drawable.icon_order_marker;
        return 0;
    }

    @Override
    public int getActionBarRightResourceId(){
        //return R.drawable.icon_search;
        return R.drawable.icon_order_marker;
    }
    //on right click
    @Override
    public void onActionBarRightClick(){
        /*((BaseActionBarMockingActivity)getActivity()).triggerSearchUi(true);
        ((BaseActionBarMockingActivity)getActivity()).setSearchListener(getOrderListFragment());*/
        Intent intent = new Intent(getActivity(), ActionBarFragmentActivity.class);
        intent.putExtra(ActionBarFragmentActivity.FRAGMENT_TITLE, R.string.map_grab_order);
        intent.putExtra(ActionBarFragmentActivity.FRAGMENT_CLASS_NAME, POIMarkerFragment.class.getName());
        intent.putExtra(MSConstants.FragmentType.class.getName(), MSConstants.FragmentType.FRAGMENT_GRABORDERS);
        getActivity().startActivity(intent);
    }

    @Override
    public boolean onBackPressed() {
        return false;
    }

    //on right click
    @Override
    public void onActionBarRight2Click(){
        Intent intent = new Intent(getActivity(), ActionBarFragmentActivity.class);
        intent.putExtra(ActionBarFragmentActivity.FRAGMENT_TITLE, R.string.map_grab_order);
        intent.putExtra(ActionBarFragmentActivity.FRAGMENT_CLASS_NAME, POIMarkerFragment.class.getName());
        intent.putExtra(MSConstants.FragmentType.class.getName(), MSConstants.FragmentType.FRAGMENT_GRABORDERS);
        getActivity().startActivity(intent);
    }
}
